/**
 * 
 * @author Lenin Medeiros (lenin.medeiros@gmail.com)
 */
package desmontec.sistema;


class UsuarioController {
	
	def springSecurityService

    /*def index = { }*/
	
	/*def init = {
		
	}*/
	
	def init = {
		def userRole = SecRole.findByAuthority('ROLE_USER') ?: new SecRole(authority: 'ROLE_USER').save(failOnError: true)
		def adminRole = SecRole.findByAuthority('ROLE_ADMIN') ?: new SecRole(authority: 'ROLE_ADMIN').save(failOnError: true)
		def adminUser = SecUser.findByUsername('admin') ?: new SecUser(			
							username: 'admin',			
							password: springSecurityService.encodePassword('admin'),			
							enabled: true).save(failOnError: true)			
					if (!adminUser.authorities.contains(adminRole)) {			
						SecUserSecRole.create adminUser, adminRole			
					}		
		}
}
